
// 图层树z-tree  setting
var layersetting = {

    callback: {
        onCheck: layerTreeOnCheck,
        onClick: layerTreeOnClick,
    },
    check: {
        autoCheckTrigger: true,
        enable: true,//显示复选框
        chkStyle: "checkbox"
    },
    key: {
        name: "name",
        title: "name"
    },
    async: {
        enable: true,//要开启async功能必须设置为true,其他地方同理
    },
    data: {
        key: {
            name: "layerName",
        },
        simpleData: {
            enable: true,
            idKey: "layerId",//节点id名
            pIdKey: "parentId",//父节点id名
            rootPId: 0//默认根节点为0
        }
    }
};

$(function () {
//图层树
    $.ajax({
        type: "POST",
        url: prefix2 + "/list",
        data: {},//发送到服务器的数据
        dataType: "json",
        success: function (data) {
            zTreeNodes = data.rows;
            console.log(data.rows);
            $.fn.zTree.init($("#layertree"), layersetting, zTreeNodes);
        }
    });
});

// z-tree选取事件
function layerTreeOnCheck(event, treeId, treeNode) {
    if (treeNode.checked){
        addCustomLayer(treeNode.layerName,treeNode.layerType,treeNode.layerUrl);
    }else if (!treeNode.checked){
        removeCustomLayer(treeNode.layerName,treeNode.layerType,treeNode.layerUrl)
    }
}

function layerTreeOnClick(event, treeId, treeNode) {
    //预定飞行跳转角度
}

